package com.lagou.edu.ssssession.controller;

import com.lagou.edu.ssssession.form.ResumeForm;
import com.lagou.edu.ssssession.pojo.Resume;
import com.lagou.edu.ssssession.service.IResumeService;
import com.lagou.edu.ssssession.vo.Result;
import com.lagou.edu.ssssession.vo.ResumeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/resume")
@Controller
public class ResumeController {

    @Autowired
    private IResumeService resumeService;

    @GetMapping("/index")
    public String  index(){
        return "/resume/index";
    }

    @GetMapping("/list")
    @ResponseBody
    public List<Resume>  list(){
        List<Resume> resumes = resumeService.queryAll();
        return resumes;
    }
    @PostMapping
    @ResponseBody
    public Result add(@RequestBody ResumeForm form) throws Exception {
        ResumeVo resumeVo = resumeService.addResume(form.toDto());
        return Result.success(resumeVo);
    }
    @DeleteMapping(value = "/{id}")
    @ResponseBody
    public Result delete(@PathVariable("id") Long id) throws Exception {
        resumeService.deleteResume(id);
        return Result.success(null);
    }
    @PutMapping
    @ResponseBody
    public Result update(@RequestBody ResumeForm form) throws Exception {
        ResumeVo resumeVo = resumeService.addResume(form.toDto());
        return Result.success(resumeVo);
    }
    @GetMapping(value = "/{id}")
    @ResponseBody
    public Result get(@PathVariable("id") Long id) throws Exception {
        ResumeVo resumeVo = resumeService.get(id);
        return Result.success(resumeVo);
    }

}
